from django.db import models

class Product(models.Model):
    STATUS_CHOICES = (
        (0, '禁用'),
        (1, '启用'),
    )

    name = models.CharField('商品名称', max_length=100)
    code = models.CharField('商品编码', max_length=50, unique=True)
    unit = models.CharField('单位', max_length=10)
    purchase_price = models.DecimalField('采购价', max_digits=10, decimal_places=2)
    sale_price = models.DecimalField('销售价', max_digits=10, decimal_places=2)
    stock = models.IntegerField('库存', default=0)
    warning_stock = models.IntegerField('预警库存', default=0)
    status = models.IntegerField('状态', choices=STATUS_CHOICES, default=1)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    update_time = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        verbose_name = '商品'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']

    def __str__(self):
        return self.name 